package com.zf.shopping.service.impl;

import com.zf.shopping.bean.GetResult;
import com.zf.shopping.bean.Result;
import com.zf.shopping.dao.AdminMapper;
import com.zf.shopping.model.Admin;
import com.zf.shopping.model.AdminExample;
import com.zf.shopping.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService{

    @Autowired
    private AdminMapper adminMapper;

    /**
     * 登录
     * @param password
     * @param number
     * @return
     */
    @Override
    public Result login(String password, Long number) {

        Admin admin = null;
        AdminExample adminE = new AdminExample();
        adminE.or().andNumberEqualTo(number);
        try {
            List<Admin> admins = adminMapper.selectByExample(adminE);
            /*账号错误*/
            if (admins.size() == 0) {
                return GetResult.fail();
            }

            admin = admins.get(0);
            /*密码错误*/
            if (!admin.getPassword().equals(password)) {
                return GetResult.fail();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return GetResult.fail();
        }

        return GetResult.success();
    }
}
